package com.examples.font;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class FontEnhanced {
	
	public static void main(String[] args) {
		final Display d = new Display();
		final Shell s = new Shell(d);
		s.setLayout(new GridLayout(2, false));
		
		final Label l = new Label(s, SWT.NONE);
		l.setText("The selected font");
		
		Button b = new Button(s, SWT.PUSH);
		b.setText("Select Font");
		
		b.addSelectionListener(new SelectionListener() {
			
			@SuppressWarnings("deprecation")
			@Override
			public void widgetSelected(SelectionEvent e) {
				FontDialog fd = new FontDialog(s);
				fd.open();
				
				@SuppressWarnings("deprecation")
				FontData f = fd.getFontData();
				l.setFont(new Font(d, f));
				l.setForeground(new Color(d, fd.getRGB()));
				
				s.pack();
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
			}
		});
		s.open();
		while(!s.isDisposed()){
			if(!d.readAndDispatch()){
				d.sleep();
			}
			//d.dispose(); //Commented only for SWTShowcase application.
		}
	}
	
}
